home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / ALCKEY.ZIP / ALCKEY.C < prev    next >
C/C++ Source or Header  |  1993-03-08  |  20KB  |  616 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM:  alckey
  4.  
  5.     PURPOSE:  Microsoft Sample Application that demonstrates ALC_ flags
  6.               and the ShowKeyboard API for Windows for Pens.
  7.               
  8.               Author:  Cynthia G. Anderson, 
  9.                        PSS Developer Support, Windows SDK Developer Support
  10.               Created: 9/15/92
  11.  
  12.     FUNCTIONS:
  13.  
  14.          WinMain() - calls initialization function, processes message loop
  15.          MainWndProc() - processes messages
  16.          About() - processes messages for "About" dialog box
  17.          InitApplication() - initializes window data and registers window
  18.          InitInstance() - saves instance handle and creates main window
  19.          AlcDlgProc() - Dialog procedure for setting ALC options
  20.          SetAlcBits() - sets bits if ALC_BITMAP selected in ALC Dialog
  21.          
  22. ****************************************************************************/
  23.  
  24. // COPYRIGHT:
  25. //
  26. //   (C) Copyright Microsoft Corp. 1993.  All rights reserved.
  27. //
  28. //   You have a royalty-free right to use, modify, reproduce and
  29. //   distribute the Sample Files (and/or any modified version) in
  30. //   any way you find useful, provided that you agree that
  31. //   Microsoft has no warranty obligations or liability for any
  32. //   Sample Application Files which are modified.
  33. //
  34.  
  35. #include "windows.h"
  36. #include "penwin.h"
  37. #include "string.h"
  38. #include "math.h"
  39. #include "stdlib.h"
  40. #include "alckey.h"
  41.  
  42.  
  43. int _pascal WinMain( HANDLE, HANDLE, LPSTR, int );
  44. long _far _pascal MainWndProc( HWND, unsigned, WORD, LONG );
  45. BOOL _far _pascal About( HWND, unsigned, WORD, LONG );
  46. BOOL _far _pascal AlcDlgProc( HWND, unsigned, WORD, LONG );
  47. static BOOL InitApplication( HANDLE );
  48. static BOOL InitInstance( HANDLE, int );
  49. VOID SetAlcBits (LPRC lprc, LPSTR lp);
  50.  
  51.  
  52. static HANDLE hInst;
  53. static HWND   hwnd;            /* handle to main window */
  54. static HWND   hWndHedit, hWndBedit;  /* handle to child windows..hedit and bedit */
  55. static HWND   hWndKeyBdButton;  /* handle to pen windows keyboard button*/
  56. static HWND   hWndAlcButton;  /* handle to alc settings button */
  57. static HWND   heditFocusWnd = NULL;  //keeper of the last window to have focus
  58. static HWND   hPenWin;               /* handle to penwin.dll if present */
  59. static HBITMAP  hKBUp, hKBDown;   /* showkeyboard bitmaps handles */
  60.  
  61.  
  62. /****************************************************************************
  63.  
  64.     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  65.  
  66.     PURPOSE: calls initialization function, processes message loop
  67.  
  68. ****************************************************************************/
  69.  
  70. int _pascal WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  71.                     LPSTR lpCmdLine,  int nCmdShow)
  72.     {
  73.     MSG msg;
  74.  
  75.     if (hPrevInstance == 0)
  76.         if (InitApplication(hInstance) == 0)
  77.             return (FALSE);
  78.  
  79.     if (InitInstance(hInstance, nCmdShow) == 0)
  80.         return (FALSE);
  81.  
  82.     while (GetMessage(&msg, 0, 0, 0) != 0)
  83.         {
  84.         TranslateMessage(&msg);
  85.         DispatchMessage(&msg);
  86.         }
  87.  
  88.     return (msg.wParam);
  89.     }
  90.  
  91.  
  92. /****************************************************************************
  93.  
  94.     FUNCTION: InitApplication(HANDLE)
  95.  
  96.     PURPOSE: Initializes window data and registers window class
  97.  
  98. ****************************************************************************/
  99.  
  100. static BOOL InitApplication(HANDLE hInstance)
  101.     {
  102.     WNDCLASS  wc;
  103.     char      szMenu[11], szClass[12];
  104.  
  105.     LoadString (hInstance, ID_MENUSTR, szMenu, sizeof (szMenu));
  106.     LoadString (hInstance, ID_CLASSSTR, szClass, sizeof (szClass));
  107.  
  108.     wc.style          = 0;
  109.     wc.lpfnWndProc    = (WNDPROC)MainWndProc;
  110.     wc.cbClsExtra     = 0;
  111.     wc.cbWndExtra     = 0;
  112.     wc.hInstance      = hInstance;
  113.     wc.hIcon          = LoadIcon(hInstance, "ALCKEY");
  114.     wc.hCursor        = LoadCursor(0, IDC_ARROW);
  115.     wc.hbrBackground  = (HBRUSH)COLOR_WINDOW+1 ;
  116.     wc.lpszMenuName   = szMenu;
  117.     wc.lpszClassName  = szClass;
  118.  
  119.     return (RegisterClass(&wc));
  120.     }
  121.  
  122.  
  123. /****************************************************************************
  124.  
  125.     FUNCTION:  InitInstance(HANDLE, int)
  126.  
  127.     PURPOSE:  Saves instance handle and creates main window
  128.  
  129. ****************************************************************************/
  130.  
  131. static BOOL InitInstance(HANDLE hInstance, int nCmdShow)
  132.     {
  133.     char szClass[12], szTitle[40];
  134.  
  135.     LoadString (hInstance, ID_CLASSSTR, szClass, sizeof (szClass));
  136.     LoadString (hInstance, ID_CAPTIONSTR, szTitle, sizeof (szTitle));
  137.  
  138.     hInst = hInstance;
  139.  
  140.     hwnd = CreateWindow(
  141.              szClass,
  142.              szTitle,
  143.              WS_OVERLAPPEDWINDOW,
  144.              CW_USEDEFAULT,
  145.              CW_USEDEFAULT,
  146.              CW_USEDEFAULT,
  147.              CW_USEDEFAULT,
  148.              0,
  149.              0,
  150.              hInstance,
  151.              0 );
  152.  
  153.     if (hwnd == 0 )
  154.         return ( FALSE );
  155.  
  156.     ShowWindow(hwnd, nCmdShow);
  157.     UpdateWindow(hwnd);
  158.     return (TRUE);
  159.     }
  160.  
  161.  
  162. /****************************************************************************
  163.  
  164.     FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
  165.  
  166.     PURPOSE:  Processes messages
  167.  
  168.           
  169. ****************************************************************************/
  170.  
  171. long _far _pascal MainWndProc(HWND hWnd, unsigned message,
  172.                               WORD wParam, LONG lParam)
  173.     {
  174.  
  175.     FARPROC  lpProcAbout, lpProcAlcDlg;
  176.     char szDlgBox[9], szMsgBoxCap[12], szStatus1[14], szStatus2[14];
  177.     char szAlcDlgBox[10];
  178.  
  179.     LoadString (hInst, ID_DLGBOX, szDlgBox, sizeof (szDlgBox));
  180.     LoadString (hInst, ID_MSGBOXCAP, szMsgBoxCap, sizeof (szMsgBoxCap));
  181.     LoadString (hInst, ID_STATUS1, szStatus1, sizeof (szStatus1));
  182.     LoadString (hInst, ID_STATUS2, szStatus2, sizeof (szStatus2));
  183.     
  184.     LoadString (hInst, ID_ALCDLGBOX, szAlcDlgBox, sizeof(szAlcDlgBox));
  185.     
  186.  
  187.     switch ( message )
  188.         {
  189.         case WM_CREATE:
  190.          {
  191.          RECT crect;
  192.          int x,y,cx,cy;
  193.          
  194.          //create keyboard button top,left corner
  195.          x=y=0;
  196.          cx=cy=40;    //make buttons 40 pixels square
  197.          hWndKeyBdButton = CreateWindow(
  198.                             (LPSTR)"button",
  199.                             (LPSTR)"ShowKeyBoard",
  200.                             WS_CHILD|WS_VISIBLE | WS_BORDER|BS_OWNERDRAW,
  201.                             x,
  202.                             y,
  203.                             cx,
  204.                             cy,
  205.                             hWnd, 
  206.                             IDC_KEYBDBUTTON,
  207.                             GetWindowWord(hWnd, GWW_HINSTANCE),
  208.                             (LPSTR)NULL);
  209.          
  210.          //load up the keyboard bitmaps, discard when app closes.
  211.          hPenWin = GetSystemMetrics(SM_PENWINDOWS);
  212.  
  213.          hKBDown = LoadBitmap(hPenWin, MAKEINTRESOURCE(OBM_SKBBTNDOWN));
  214.          hKBUp = LoadBitmap(hPenWin, MAKEINTRESOURCE(OBM_SKBBTNUP));
  215.          
  216.          //create alc settings button top,left corner next to keyboard button
  217.          x=40; y=0;
  218.          cx=cy=40;
  219.          hWndAlcButton = CreateWindow(
  220.                             (LPSTR)"button",
  221.                             (LPSTR)"ALC",
  222.                             WS_CHILD|WS_VISIBLE | WS_BORDER,
  223.                             x,
  224.                             y,
  225.                             cx,
  226.                             cy,
  227.                             hWnd, 
  228.                             IDC_ALCBUTTON,
  229.                             GetWindowWord(hWnd, GWW_HINSTANCE),
  230.                             (LPSTR)NULL);
  231.                
  232.          // create two edit controls, an hedit and a bedit
  233.          GetClientRect(hWnd, &crect);
  234.          
  235.          x =  (crect.right-crect.left)/8;
  236.          cx = (crect.right-crect.left)*4/8;
  237.          y =  (crect.bottom-crect.top)/8;
  238.          cy = (crect.bottom-crect.top)*2/8;
  239.          
  240.          hWndHedit = CreateWindow(
  241.                (LPSTR)"hedit",
  242.                (LPSTR)NULL,
  243.                WS_CHILD|WS_VISIBLE |ES_MULTIL